<!DOCTYPE html>
<html>
<head>
<title>Thermodynamic Process Diagram</title>
</head>
<body>

<canvas id="physicsCanvas" width="600" height="250"></canvas>

<script>
const canvas = document.getElementById('physicsCanvas');
const ctx = canvas.getContext('2d');

// --- Configuration ---
const boxWidth = 220;
const boxHeight = 110;
const leftBoxX = 40;
const rightBoxX = 340;
const boxY = 40;

const baseFont = "24px Arial";
const supFont = "16px Arial";
const labelFont = "bold 24px Arial";
const baseFontSize = 24; // Corresponds to baseFont size

// --- Drawing Functions ---

// Function to draw a line of text, possibly with superscripts, centered horizontally.
function drawCenteredScientificLine(centerX, y, parts) {
    // Calculate the total width of the line first
    let totalWidth = 0;
    parts.forEach(part => {
        ctx.font = (part.type === 'sup') ? supFont : baseFont;
        totalWidth += ctx.measureText(part.text).width;
    });

    // Determine the starting x-coordinate for the line
    let currentX = centerX - totalWidth / 2;

    // Draw each part of the line sequentially
    ctx.textAlign = 'left';
    parts.forEach(part => {
        if (part.type === 'sup') {
            ctx.font = supFont;
            // Adjust y for superscript
            ctx.fillText(part.text, currentX, y - baseFontSize * 0.4);
        } else {
            ctx.font = baseFont;
            ctx.fillText(part.text, currentX, y);
        }
        
        // Move currentX for the next part
        ctx.font = (part.type === 'sup') ? supFont : baseFont;
        currentX += ctx.measureText(part.text).width;
    });
}

// --- Main Drawing Logic ---

// Set common styles
ctx.strokeStyle = 'black';
ctx.fillStyle = 'black';
ctx.lineWidth = 2;

// Draw Left Box and its contents
ctx.strokeRect(leftBoxX, boxY, boxWidth, boxHeight);
const leftBoxCenterX = leftBoxX + boxWidth / 2;
let y_pos_left = boxY + 35;

const line1_parts = [
    { text: '2.40 × 10', type: 'base' },
    { text: '3', type: 'sup' },
    { text: ' cm', type: 'base' },
    { text: '3', type: 'sup' }
];
drawCenteredScientificLine(leftBoxCenterX, y_pos_left, line1_parts);

y_pos_left += 35;
const line2_parts_left = [
    { text: '3.51 × 10', type: 'base' },
    { text: '5', type: 'sup' },
    { text: ' Pa', type: 'base' }
];
drawCenteredScientificLine(leftBoxCenterX, y_pos_left, line2_parts_left);

y_pos_left += 35;
ctx.font = baseFont;
ctx.textAlign = 'center';
ctx.fillText('290 K', leftBoxCenterX, y_pos_left);

// Draw Right Box and its contents
ctx.strokeRect(rightBoxX, boxY, boxWidth, boxHeight);
const rightBoxCenterX = rightBoxX + boxWidth / 2;
let y_pos_right = boxY + 35;

// Line 1 is the same for both boxes
drawCenteredScientificLine(rightBoxCenterX, y_pos_right, line1_parts);

y_pos_right += 35;
const line2_parts_right = [
    { text: '3.75 × 10', type: 'base' },
    { text: '5', type: 'sup' },
    { text: ' Pa', type: 'base' }
];
drawCenteredScientificLine(rightBoxCenterX, y_pos_right, line2_parts_right);

y_pos_right += 35;
ctx.font = baseFont;
ctx.textAlign = 'center';
ctx.fillText('310 K', rightBoxCenterX, y_pos_right);

// Draw the Arrow between boxes
const arrowY = boxY + boxHeight / 2;
const arrowStartX = leftBoxX + boxWidth;
const arrowEndX = rightBoxX;
ctx.beginPath();
ctx.moveTo(arrowStartX, arrowY);
ctx.lineTo(arrowEndX, arrowY);
// Arrowhead
ctx.moveTo(arrowEndX, arrowY);
ctx.lineTo(arrowEndX - 12, arrowY - 6);
ctx.moveTo(arrowEndX, arrowY);
ctx.lineTo(arrowEndX - 12, arrowY + 6);
ctx.stroke();

// Draw the Figure Label
ctx.font = labelFont;
ctx.textAlign = 'center';
ctx.fillText('Fig. 2.1', (arrowStartX + arrowEndX) / 2, 210);

</script>

</body>
</html>